package net.zjitc.service.impl;

import net.zjitc.dao.CartDao;
import net.zjitc.dao.OrderDao;
import net.zjitc.dao.impl.CartDaoImpl;
import net.zjitc.dao.impl.OrderDaoImpl;
import net.zjitc.pojo.Order;
import net.zjitc.service.OrderService;
import net.zjitc.utils.db.C3P0Utils;

import java.sql.SQLException;

/**
 * Created by Administrator on 2017/12/14.
 */
public class OrderServiceImpl implements OrderService {
    CartDao cartDao = new CartDaoImpl();
    OrderDao orderDao = new OrderDaoImpl();
    public int add(Order order) {
        try{
            C3P0Utils.startTransation();
            orderDao.add(order);
            cartDao.deleteByUid(order.getUser().getUid());
            C3P0Utils.commitTransation();
        } catch (SQLException e) {
            try{
                C3P0Utils.rollbackTransation();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }
        return 0;
    }
}
